<template>
  <div>
    <a-select
      v-model="data"
      show-search
      placeholder="请选择"
      option-filter-prop="children"
      @change="handleChange"
    >
      <a-select-option v-for="supplier in supplierList" :key="supplier.id" :value="supplier.id">
        {{supplier.name}}
      </a-select-option>
    </a-select>
  </div>
</template>

<script>
  import { getSupplierList } from '@/api/supplier'

  export default {
    name: 'SupplierSelect',
    props: {
      value: {
        type: Number,
        default: null
      }
    },
    watch: {
      value (val) {
        this.data = val
      }
    },
    created () {
      getSupplierList({ per_page: 999 }).then(res => {
        this.supplierList = res.data
      })
    },
    data () {
      return {
        data: null,
        supplierList: []
      }
    },
    methods: {
      handleChange (value) {
        this.$emit('change', value)
        this.$emit('input', value)
      }
    }
  }
</script>

<style scoped>

</style>
